<template>
  <div class="form-container">
    <div class="form-content">
      <div class="main-left">
        <div class="title">Dev-CodePulse</div>
      </div>
      <div class="main-right">
        <div style="width: 100%">
          <h4 class="title">{{ currentLoginType === 1 ? '登录' : '注册' }}</h4>
          <div>
            <div>
              <login-by-phone v-if="currentLoginType === 1" />
              <register v-if="currentLoginType === 2" />
            </div>
            <div class="switch-wrap" v-if="currentLoginType !== 2">
              <div class="ways">
                <span>其他登录方式</span>
              </div>
              <ul class="other-ways">
                <template v-for="(item, index) in loginTypes" :key="index">
                  <li v-if="item.type !== currentLoginType" @click="currentLoginType = item.type">
                    <div class="inline-container">
                      <i :class="['iconfont', item.icon]" />
                      <span class="desc">{{ item.name }}</span>
                    </div>
                  </li>
                </template>
              </ul>
            </div>
          </div>
        </div>
        <div class="login-bottom">
          <a-button @click="toRegisterOrLogin">{{
            currentLoginType === 1 ? '没有账号?去注册' : '已有账号?去登录'
          }}</a-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import LoginByPhone from '@/views/system/login/components/pages/LoginByPhone.vue'
import Register from '@/views/system/login/components/pages/Register.vue'

const currentLoginType = ref(1)
const loginTypes = reactive([
  {
    type: 3,
    name: '邮箱',
    icon: 'icon-youxiang'
  },
  {
    type: 4,
    name: '微信',
    icon: 'icon-weixindenglu_weixin'
  },
  {
    type: 5,
    name: '扫码',
    icon: 'icon-saomadenglu'
  },
  {
    type: 1,
    name: '手机号',
    icon: 'icon-denglu_shoujihaodenglu_shoujihao'
  }
])

const toRegisterOrLogin = () => {
  currentLoginType.value === 1 ? (currentLoginType.value = 2) : (currentLoginType.value = 1)
}
</script>

<style scoped lang="scss">
.form-container {
  transform-origin: top;
  display: flex;
  justify-content: center;
  margin: 40px 0;

  .form-content {
    display: flex;
    justify-content: center;
    align-items: center;

    .main-left {
      display: flex;
      flex-direction: column;
      margin-right: 134px;

      .title {
        font-weight: 600;
        font-size: 24px;
        line-height: 32px;
        display: flex;
        align-items: center;
        position: relative;
      }
    }

    .main-right {
      overflow: hidden;
      width: 560px;
      min-height: 480px;
      background: linear-gradient(180deg, hsla(0, 0%, 100%, 0.9), hsla(0, 0%, 100%, 0.75));
      border: 2px solid #fff;
      box-shadow: 0 20px 50px rgba(29, 42, 165, 0.05);
      -webkit-backdrop-filter: blur(7.5px);
      backdrop-filter: blur(7.5px);
      border-radius: 8px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      padding: 64px 80px 34px;

      .title {
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 32px;
        margin-bottom: 24px;
        font-size: 24px;
        font-weight: 600;
      }

      .switch-wrap {
        margin-top: 30px;
        text-align: center;
        -webkit-user-select: none;
        -ms-user-select: none;
        user-select: none;

        .ways {
          display: flex;
          align-items: center;
          justify-content: space-around;
          width: 100%;
          height: 20px;
          line-height: 20px;
          margin-bottom: 24px;
          span {
            display: inline-block;
            height: 100%;
            padding: 0 24px;
            z-index: 2;
            color: #8892a4;
            font-size: 14px;
            font-weight: 400;
          }
        }

        .ways:after,
        .ways:before {
          content: '';
          flex: 1 1;
          height: 1px;
          background: rgba(136, 146, 164, 0.4);
        }

        .other-ways {
          display: flex;
          justify-content: center;
          align-items: flex-start;
          flex-wrap: wrap;
          margin: 0;
          padding: 0;
          list-style: none;
          font-size: 14px;
          font-weight: 400;

          li {
            position: relative;
            margin: 0;
            padding: 0;
            display: flex;
            flex: 0 0 20%;
            justify-content: center;
            align-items: center;
            color: #202d40;
            font-size: 14px;
            font-weight: 400;

            .inline-container {
              display: flex;
              flex-direction: column;
              justify-content: center;
              align-items: center;
              text-align: center;
              cursor: pointer;
              .iconfont {
                font-size: 24px;
              }
              .desc {
                display: block;
                line-height: 22px;
                margin: 4px 0 0;
                font-size: 14px;
                color: rgba(20, 24, 30, 0.7490196078431373);
              }
            }
          }
        }
      }

      .login-bottom {
        margin-top: 32px;
      }
    }
  }
}
</style>
